package com.bdth.mixapi.api.controller.index;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bdth.mixapi.api.entity.Device;
import com.bdth.mixapi.api.entity.Pushmsg;
import com.bdth.mixapi.api.entity.Xjlog;
import com.bdth.mixapi.api.service.PushmsgService;
import com.bdth.mixapi.api.service.XjlogService;
import com.bdth.mixapi.api.vo.CommonList;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author LGP
 * @since 2019-04-22
 */
@Api("首页数据推送日志")
@RestController
@RequestMapping("/index")
public class PushmsgController {
    @Autowired
    PushmsgService pushmsgService;

    @Autowired
    XjlogService xjlogService;

    @ApiOperation(value="数据推送日志前N条")
    @RequestMapping(value = "pushmsg/list", method = RequestMethod.GET)
    public CommonList<Pushmsg> getList(@RequestParam int top){
        QueryWrapper<Pushmsg> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("id");
        queryWrapper.last("limit "+top);
        List<Pushmsg> list = pushmsgService.list(queryWrapper);
        return CommonList.success(list);
    }

    @ApiOperation(value="新疆dataV日志前N条")
    @RequestMapping(value = "xjlog/list", method = RequestMethod.GET)
    public Object[] getXjList(@RequestParam int top){
        Object[] r = new Object[1];
        QueryWrapper<Xjlog> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("id");
        queryWrapper.last("limit "+top);
        List<Xjlog> list = xjlogService.list(queryWrapper);
        Map<String,String> result = new HashMap<>();
        result.put("value","");
        String str = "";
        for (Xjlog bean: list) {
            str += bean.getValue();
        }
        result.put("value",str);
        r[0] = result;
        return r;
    }
}
